package com.wazzapps.sdk.utils;

import android.content.Context;
import android.telephony.TelephonyManager;

import java.util.Locale;

public class Tools {
    public static String getCountryFromNetwork(Context context) {
        return getCountryFromNetwork(context, null);
    }
    public static String getCountryFromNetwork(Context context, String str) {
        String networkCountryIso;
        try {
            TelephonyManager telephonyManager = (TelephonyManager) context.getApplicationContext().getSystemService("phone");
            String simCountryIso = telephonyManager.getSimCountryIso();
            if (simCountryIso != null && simCountryIso.length() == 2) {
                return simCountryIso.toUpperCase(Locale.US);
            }
            if (!(telephonyManager.getPhoneType() == 2 || (networkCountryIso = telephonyManager.getNetworkCountryIso()) == null)) {
                return networkCountryIso.toUpperCase(Locale.US);
            }
            return str;
        } catch (Exception ignored) { }
        return "null";
    }
}